using System;
using Science.Mathematics;
using L=Science.Physics.GeneralPhysics;

namespace Serway.Chapter07
{
	/// <summary>
	/// Example06: Measuring K for a Spring
	/// A common technique used to measure the force constant 
	/// of a spring is demonstrated by the setup in Figure 7.12. 
	/// The spring is hung vertically, and an object of mass m 
	/// is attached to its lower end. Under the action of 
	/// the "load" mg, the spring stretches a distance d from 
	/// its equilibrium position.
	/// (A) If a spring is stretched 2.0 cm by a suspended object 
	/// having a mass of 0.55 kg.
	/// what is the force constant of the spring?
	/// k = 2.7 \times 10^2 N/m
	/// (B) How much work is done by the spring as it stretches
	/// through this distance?
	/// W = -5.4 \times 10^{-2} J
	/// </summary>
	public class Example06
	{
		public Example06()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
		public void Compute()
		{
			L.Mass m = new L.Mass();
			m.kg = 0.55;
			double k = 0.55*L.Constant.AccelerationOfGravity/0.02;
			result = Convert.ToString(k)+"    ";
			L.Vector.FunctionOfPosition func = new L.Vector.FunctionOfPosition(FvsX);
			L.Force f = new L.Force();
            f.VectorFunctionOfPosition = func;
			L.Line.Parameterization pf = new L.Line.Parameterization(XvsT);
			L.Line p = new L.Line(pf);
			p.ParameterStartValue = 0.0;
			p.ParameterEndValue = 0.02;
			L.Work w = new L.Work(f,p);
			result += Convert.ToString(w.J);
		}
		private L.Vector FvsX(L.Position x)
		{
			L.Vector force = new L.Vector();
		    force.X = -0.55*L.Constant.AccelerationOfGravity/0.02*x.X;
			return force;
		}
		private L.Position XvsT(double t)
		{
			L.Position x = new L.Position();
			x.X = t;
			return x;
		}
	}
}
